package com.wn.framework.utils

import android.app.Activity
import android.content.Context
import com.wn.framework.loading.CenterLoadingView

/**
 * @Author: wn
 * @Date: 2024/8/21 16:38
 * @Description: 等待提示框
 */
class LoadingUtils(private val mContext: Context) {
  private val loadView: CenterLoadingView by lazy {
    CenterLoadingView(mContext)
  }

  /**
   * 展示耗时操作 Dialog
   */
  fun showLoading(txt: String) {
    // 当 Activity 销毁后 不执行
    if (mContext is Activity && mContext.isFinishing) {
      return
    }
    loadView.apply {
      //  requestWindowFeature(Window.FEATURE_NO_TITLE)
      // 已经在展示中 就先 关闭 弹框
      if (isShowing) dismiss()
      // 不为空
      setTitle(txt as CharSequence)
      // 展示
      show()
    }
  }

  /**
   * 关闭 Dialog
   */
  fun dismissLoading() {
    if (mContext is Activity && mContext.isFinishing) {
      return
    }
    loadView.apply {
      if (isShowing) dismiss()
    }
  }
}
